<template>
  <!-- 分配权限的弹层 -->
  <el-dialog title="分配权限" :visible="showAssignDialog" @close="closeAssignDialog" @open="opensetlist">
    内容部分
    <el-tree
      ref="tree"
      v-loading="treeLoading"
      :data="openyserlists"
      :props="{ label: 'name' }"
      :default-expand-all="true"
      :show-checkbox="true"
      :check-strictly="true"
      node-key="id"
    />
    <template #footer>
      <div style="text-align: right;">
        <el-button @click="closeAssignDialog">取消</el-button>
        <el-button type="primary" @click="thinklist">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { permissionListAPI } from '@/api/permission'
import { getxiugaiAPI, fenpeisuerAPI } from '@/api/setting'
import { truesListData } from '@/utils/index'
export default {
  props: {
    showAssignDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      retdid: '',
      openyserlists: [],
      treeLoading: false
    }
  },
  methods: {
    closeAssignDialog() {
      this.$emit('update:showAssignDialog', false)
    },
    /**
     * 打开时发送请求
     */
    opensetlist() {
      this.openyserlist()
      this.huilist()
    },
    /**
     * 获取权限列表数据
     */
    async openyserlist() {
      const { data: res } = await permissionListAPI()
      console.log(res)
      this.openyserlists = truesListData(res, '0')
    },
    /**
     * 回显数据
     */
    async huilist(id) {
      console.log(this.retdid)
      const { data: res } = await getxiugaiAPI(id)
      console.log(res)
      this.$refs.tree.setCheckedKeys(res.permIds)
      this.treeLoading = false
    },
    /**
     * 分配权限角色
     */
    async thinklist() {
      console.log(this.retdid)
      console.log(this.permIds)
      await fenpeisuerAPI({
        // console.log(111);
        id: this.retdid,
        roleIds: this.$refs.tree.getCheckedKeys()
      })
      this.$message.success('成功')
    }
  }
}
</script>

<style>

</style>
